<template>
  <!-- 校历页面 -->
  <div class="app-container">
    <!-- 搜索 -->
    <searchForm :formOptions="formOptions" @onReset="onReset" :formLabelWidth = 'formLabelWidth' @onSearch="onSearch" />
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <right-toolbar @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table :data="tableData">
      <el-table-column prop="name" label="姓名"> </el-table-column>
      <el-table-column prop="name" label="单位"> </el-table-column>
      <el-table-column prop="name" label="性别"> </el-table-column>
      <el-table-column prop="name" label="教工号"> </el-table-column>X
      <el-table-column prop="name" label="当前状态"> </el-table-column>
      <el-table-column prop="name" label="是否使用"> </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scop.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 教职工添加或修改 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位" prop="nickName">
              <el-cascader
                v-model="form.value"
                :options="options"
                @change="handleChange"
                style="width: 100%"
                placeholder="请选择"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="教工号" prop="roleName">
              <el-input v-model="form.ZZC" placeholder="请输入教工号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="roleName">
              <el-input v-model="form.ZZC" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="nickName">
              <el-select
                v-model="form.XQ"
                multiple
                placeholder="请选择性别"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="nickName">
              <el-select
                v-model="form.XSLX"
                multiple
                placeholder="请选择状态"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否使用" prop="nickName">
              <el-select
                v-model="form.XSLX"
                multiple
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import searchForm from "@/components/Search/searchForm.vue";
export default {
  components: { searchForm },
  dicts: ["sys_normal_disable"],
  data() {
    return {
      formLabelWidth: "60px",
      formOptions: [
        {
          label: "单位",
          prop: "type",
          element: "el-select",
          options: [
            { label: "给点意见", value: "1" },
            { label: "售后问题", value: "2" },
          ],
          placeholder: "请选择单位",
        },
        {
          label: "姓名",
          prop: "XM",
          element: "el-input",
          placeholder: "请输入姓名",
        },
        {
          label: "教工号",
          prop: "JGH",
          element: "el-input",
          placeholder: "请输入教工号",
        },
      ],
      tableData: [],
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      title: "",
      // 修改或添加弹窗
      open: false,
      form: {},
      options: [],
    };
  },
  methods: {
    handleChange(value) {
      console.log(value);
    },
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      this.queryParams = Object.assign(this.queryParams, data);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.tableData = response.rows;
          this.total = response.total;
        }
      );
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "校历添加";
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$modal
        .confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？')
        .then(function () {
          return delRole(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const roleId = row.roleId || this.ids;
      const roleMenu = this.getRoleMenuTreeselect(roleId);
      getRole(roleId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.$nextTick(() => {
          roleMenu.then((res) => {
            let checkedKeys = res.checkedKeys;
            checkedKeys.forEach((v) => {
              this.$nextTick(() => {
                this.$refs.menu.setChecked(v, true, false);
              });
            });
          });
        });
        this.title = "校历修改";
      });
    },
    // 提交新增或修改的数据
    submitForm() {},
  },
};
</script>

<style>
</style>